-- SteelDoor
-- Created by dengc Oct/11/2016
-- 钢铁之门

-- 初始化
function initSteelDoor(self)
    local class = self.gridData.class;
    local pos = self.gridData:getPos();
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            -- 先判断能否点击
            if not self.gridData:canHit() then
                alert(getLocStr("cannot_reach"));
                return;
            end

            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local function okFunc()
                DungeonActionM.go("destory_steel_door", pos);
            end

            local function cancelFunc()
                return;
            end

            -- 打开建筑查看界面
            AudioM.playFx("ui_open1");
            self:openBuildingView2(
                okFunc,
                cancelFunc
            );
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.item:setPositionY(18);
end

-- 摧毁钢铁之门
function onDestorySteelDoor(self, args)
    -- 弹出提示
    alert(getLocStr("avalon_steel_door_destory"));

    -- 爆炸光效
    playBuildingDisappearEffect(self, "bomb");

    -- 建筑物奖励
    self:onBuildingBonus({["bonus"] = args["bonus"]});
end

-- 钢铁之门转换
function onSteelDoorTrans(self, args)
    -- 弹出提示
    alert(getLocStr("avalon_steel_door_trans"));

    -- 建筑物奖励
    self:onBuildingBonus({["bonus"] = args["bonus"]}, true);
end
